let obj = {
    a:1,
    b:2,
    c:{
        d:4
    }
}

function isObject(obj){
    return obj !== null && typeof obj === "object"
}
/* obj新增是没有办法读取的,跟修改 */
function observe(obj){
    for (const key in obj) {
        if(isObject(obj[key])){
            observe(obj[key])
        }
        let v = obj[key];
        Object.defineProperty(obj,key,{
            get(){
                console.log(key, '读取')
                return v
            },
            set(val){
                if(v !==val){
                    console.log(key, '更改')
                    v = val
                }
            }
        })
       
    }
}

observe(obj)
obj.a =3
obj.b
console.log(obj.b)



